#ifndef DELAYBEAMPARAMS_H
#define DELAYBEAMPARAMS_H

#include <QSettings>
#include "jsonconvert.h"

class DelayBeamParams : public JsonConvert
{
public:
    DelayBeamParams(){}

    int laserOffDelay()
    {
        return mLaserOffDelay;
    }

    void setLaserOffDelay(int laserOffDelay)
    {
        mLaserOffDelay = laserOffDelay;
    }

    int laserOnDelay()
    {
        return mLaserOnDelay;
    }

    void setLaserOnDelay(int laserOnDelay)
    {
        mLaserOnDelay = laserOnDelay;
    }

    int jumpDelay()
    {
        return mJumpDelay;
    }

    void setJumpDelay(int jumpDelay)
    {
        mJumpDelay = jumpDelay;
    }

    int markDelay()
    {
        return mMarkDelay;
    }

    void setMarkDelay(int markDelay)
    {
        mMarkDelay = markDelay;
    }

    int polygonDelay()
    {
        return mPolygonDelay;
    }

    void setPolygonDelay(int polygonDelay)
    {
        mPolygonDelay = polygonDelay;
    }

    void readFromFile()
    {
        QSettings settings("GlobalLaser.ini", QSettings::IniFormat);
        settings.beginGroup("DelayBeamParams");
        this->mLaserOffDelay = settings.value("mLaserOffDelay", 0).toInt();
        this->mLaserOnDelay = settings.value("mLaserOnDelay", 0).toInt();
        this->mJumpDelay = settings.value("mJumpDelay", 0).toInt();
        this->mMarkDelay = settings.value("mMarkDelay", 0).toInt();
        this->mPolygonDelay = settings.value("mPolygonDelay", 0).toInt();
        settings.endGroup();
    }

    void writeToFile()
    {
        QSettings settings("GlobalLaser.ini", QSettings::IniFormat);
        settings.beginGroup("DelayBeamParams");
        settings.setValue("mLaserOffDelay", mLaserOffDelay);
        settings.setValue("mLaserOnDelay", mLaserOnDelay);
        settings.setValue("mJumpDelay", mJumpDelay);
        settings.setValue("mMarkDelay", mMarkDelay);
        settings.setValue("mPolygonDelay", mPolygonDelay);
        settings.endGroup();
    }

    QJsonObject toJsonObj() const
    {
        QJsonObject obj;
        obj["mLaserOffDelay"] = mLaserOffDelay;
        obj["mLaserOnDelay"] = mLaserOnDelay;
        obj["mJumpDelay"] = mJumpDelay;
        obj["mMarkDelay"] = mMarkDelay;
        obj["mPolygonDelay"] = mPolygonDelay;
        return obj;
    }

    void fromJsonObj(const QJsonObject& obj)
    {
        mLaserOffDelay = obj["mLaserOffDelay"].toInt();
        mLaserOnDelay = obj["mLaserOnDelay"].toInt();
        mJumpDelay = obj["mJumpDelay"].toInt();
        mMarkDelay = obj["mMarkDelay"].toInt();
        mPolygonDelay = obj["mPolygonDelay"].toInt();
    }

    bool operator ==(const DelayBeamParams& param){
        bool rel = true;
        rel &= (this->mLaserOffDelay == param.mLaserOffDelay);
        rel &= (this->mLaserOnDelay == param.mLaserOnDelay);
        rel &= (this->mJumpDelay == param.mJumpDelay);
        rel &= (this->mMarkDelay == param.mMarkDelay);
        rel &= (this->mPolygonDelay == param.mPolygonDelay);
        return rel;
    }

    void operator =(const DelayBeamParams& param){
        this->mLaserOffDelay = param.mLaserOffDelay;
        this->mLaserOnDelay = param.mLaserOnDelay;
        this->mJumpDelay = param.mJumpDelay;
        this->mMarkDelay = param.mMarkDelay;
        this->mPolygonDelay = param.mPolygonDelay;
    }

public slots:
    int mLaserOffDelay = 0;//激光关延时us
    int mLaserOnDelay = 0;//激光开延时
    int mJumpDelay = 0;//跳转延时
    int mMarkDelay = 0;//标记延时(结束延时)
    int mPolygonDelay = 0;//多边形延时(拐角延时)
};

#endif // DELAYBEAMPARAMS_H
